﻿/*  Copyright 2012 PerceiveIT Limited
 *  This file is part of the Scryber library.
 *
 *  You can redistribute Scryber and/or modify 
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  Scryber is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Scryber source code in the COPYING.txt file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using Scryber.Text;
using Scryber.Drawing;
using System.ComponentModel;

namespace Scryber.Styles.Old
{
    [PDFParsableComponent("Text")]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class PDFTextStyle : PDFStyleItem
    {
        //
        // constructors
        //

        #region .ctor() + .ctor(type)

        public PDFTextStyle()
            : this(PDFObjectTypes.StyleText, INHERITED)
        {
        }

        protected PDFTextStyle(PDFObjectType type, bool inherited)
            : base(type, inherited)
        {
        }

        #endregion


        //
        // style properties
        //

        
        #region public PDFUnit FirstLineInset {get;set;} + RemoveFirstLineInset()

        [PDFAttribute("first-indent")]
        [Obsolete("First line inset is not currently supported. Any value will be ignored",false)]
        public PDFUnit FirstLineInset
        {
            get
            {
                //PDFUnit f;
                //if (this.GetUnitValue(StyleKeys.FirstInsetAttr, false, out f))
                //    return f;
                //else
                    return PDFUnit.Empty;
            }
            set
            {
                //this.SetValue(StyleKeys.FirstInsetAttr, value.ToString(), value);
            }
        }

        public void RemoveFirstLineInset()
        {
            this.Remove(StyleKeys.FirstInsetAttr);
        }

        #endregion

        #region public float WordSpacing {get;set} + RemoveWordSpacing()

        [PDFAttribute("word-spacing")]
        public float WordSpacing
        {
            get
            {
                float f;
                if (this.GetFloatValue(StyleKeys.WordSpacingAttr, false, out f))
                    return f;
                else
                    return 1.0F;
            }
            set
            {
                this.SetValue(StyleKeys.WordSpacingAttr, value.ToString(), value);
            }
        }

        public void RemoveWordSpacing()
        {
            this.Remove(StyleKeys.WordSpacingAttr);
        }

        #endregion

        #region public WordWrap WrapText {get;set;} + RemoveWrapText()

        [PDFAttribute("wrap")]
        public WordWrap WrapText
        {
            get
            {
                object f;
                if (this.GetEnumValue(StyleKeys.WrappingAttr, typeof(WordWrap), false, out f))
                    return (WordWrap)f;
                else
                    return WordWrap.Auto;
            }
            set
            {
                this.SetValue(StyleKeys.WrappingAttr, value.ToString(), value);
            }
        }

        public void RemoveWrapText()
        {
            this.Remove(StyleKeys.WrappingAttr);
        }

        #endregion

        #region public TextDecoration Decoration {get;set;} + RemoveDecoration()

        /// <summary>
        /// Gets or sets the text decoration of the rendered characters.
        /// </summary>
        [PDFAttribute("decoration")]
        public TextDecoration Decoration
        {
            get
            {
                object decor;
                if (this.GetEnumValue(StyleKeys.DecorationAttr, typeof(TextDecoration), false, out decor))
                    return (TextDecoration)decor;
                else
                    return TextDecoration.None;
            }
            set
            {
                this.SetValue(StyleKeys.DecorationAttr, value);
            }
        }

        /// <summary>
        /// Clears any set value from this style
        /// </summary>
        public void RemoveDecoration()
        {
            this.Remove(StyleKeys.DecorationAttr);
        }

        #endregion

        #region public PDFUnit Leading {get;set;} + RemoveLeadingText()

        [PDFAttribute("leading")]
        public PDFUnit Leading
        {
            get
            {
                PDFUnit f;
                if (this.GetUnitValue(StyleKeys.FontLeadingAttr, false, out f))
                    return f;
                else
                    return PDFUnit.Zero;
            }
            set
            {
                this.SetValue(StyleKeys.FontLeadingAttr, value.ToString(), value);
            }
        }

        public void RemoveLeading()
        {
            this.Remove(StyleKeys.FontLeadingAttr);
        }

        #endregion

        #region public bool PreserveWhitespace {get;set;} + RemoveWhiteSpace()

        /// <summary>
        /// If true then all whitespace within the text component will be preserved.
        /// </summary>
        [PDFAttribute(StyleKeys.WhitespaceAttr)]
        public bool PreserveWhitespace
        {
            get
            {
                bool value;
                if (this.GetBoolValue(StyleKeys.WhitespaceAttr, false, out value))
                    return value;
                else
                    return false;
            }
            set
            {
                this.SetValue(StyleKeys.WhitespaceAttr, value.ToString(), value);
            }
        }

        public void RemoveWhitespace()
        {
            this.Remove(StyleKeys.WhitespaceAttr);
        }

        #endregion

        #region public string DateFormat {get;set;} + RemoveDateText()

        /// <summary>
        /// Gets or sets the format string which stipulates how to convert date values to a string value and display
        /// </summary>
        [PDFAttribute("date-format")]
        public string DateFormat
        {
            get
            {
                string f;
                if (this.GetStringValue(StyleKeys.DateFormatAttr, false, out f))
                    return f;
                else
                    return string.Empty;
            }
            set
            {
                this.SetValue(StyleKeys.DateFormatAttr, value.ToString(), value);
            }
        }

        public void RemoveDateFormat()
        {
            this.Remove(StyleKeys.DateFormatAttr);
        }

        #endregion

        #region public string NumberFormat {get;set;} + RemoveNumberText()

        /// <summary>
        /// Gets or sets the format string which stipulates how to convert numeric values to a string value and display
        /// </summary>
        [PDFAttribute("number-format")]
        public string NumberFormat
        {
            get
            {
                string f;
                if (this.GetStringValue(StyleKeys.NumberFormatAttr, false, out f))
                    return f;
                else
                    return string.Empty;
            }
            set
            {
                this.SetValue(StyleKeys.NumberFormatAttr, value.ToString(), value);
            }
        }

        public void RemoveNumberFormat()
        {
            this.Remove(StyleKeys.NumberFormatAttr);
        }

        #endregion
    }
}
